package com.pansoft.hd.model;

import com.pansoft.openplanet.constant.IPAssetsConstant;

import java.util.List;

/**
 * bip49的btc钱包
 */
public class BtcHdWallet extends BaseHDWallet  {

    //xpub
    private String xpub;
    //xprv
    private String xprv;
    //子地址
    private List<BtcChildAddress> btcChildAddresses;

    @Override
    public int getChainId() {
        return IPAssetsConstant.CHAIN_ID_BTC;
    }

    @Override
    public String getChainName() {
        return IPAssetsConstant.ChainEnum.BTC.chainName;
    }


    public static final class BtcHdWalletBuilder {
        //主地址， path /0/0/
        private String address;
        //私钥  16进制的
        private String privateKey;
        //公钥 16进制的
        private String publicKey;
        //xpub
        private String xpub;
        //xprv
        private String xprv;
        //子地址
        private List<BtcChildAddress> btcChildAddresses;

        private BtcHdWalletBuilder() {
        }

        public static BtcHdWalletBuilder anBtcHDWallet() {
            return new BtcHdWalletBuilder();
        }

        public BtcHdWalletBuilder withAddress(String address) {
            this.address = address;
            return this;
        }

        public BtcHdWalletBuilder withPrivateKey(String privateKey) {
            this.privateKey = privateKey;
            return this;
        }

        public BtcHdWalletBuilder withPublicKey(String publicKey) {
            this.publicKey = publicKey;
            return this;
        }

        public BtcHdWalletBuilder withXPub(String xpub) {
            this.xpub = xpub;
            return this;
        }

        public BtcHdWalletBuilder withXPrv(String xprv) {
            this.xprv = xprv;
            return this;
        }

        public BtcHdWalletBuilder withChildWallet(List<BtcChildAddress> btcChildAddresses) {
            this.btcChildAddresses = btcChildAddresses;
            return this;
        }



        public BtcHdWallet build() {
            BtcHdWallet btcHdWallet = new BtcHdWallet();
            btcHdWallet.setAddress(address);
            btcHdWallet.setPrivateKey(privateKey);
            btcHdWallet.setPublicKey(publicKey);
            btcHdWallet.setXpub(xpub);
            btcHdWallet.setXprv(xprv);
            btcHdWallet.setBtcChildAddresses(btcChildAddresses);
            return btcHdWallet;
        }
    }

    public static class BtcChildAddress{

        //路径“0/1”
        private String path;
        private String address;
        private String publicKey;
        //子地址是由xpub派生出来的，所以没有私钥
        //是否选中的当前地址
        private boolean isSelected;
        //当前子地址的位置
        private int index;
        public BtcChildAddress() {
        }

        public int getIndex() {
            return index;
        }

        public void setIndex(int index) {
            this.index = index;
        }

        public boolean isSelected() {
            return isSelected;
        }

        public void setSelected(boolean selected) {
            isSelected = selected;
        }

        public String getPath() {
            return path;
        }

        public void setPath(String path) {
            this.path = path;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getPublicKey() {
            return publicKey;
        }

        public void setPublicKey(String publicKey) {
            this.publicKey = publicKey;
        }
    }

    public String getXpub() {
        return xpub;
    }

    public void setXpub(String xpub) {
        this.xpub = xpub;
    }

    public String getXprv() {
        return xprv;
    }

    public void setXprv(String xprv) {
        this.xprv = xprv;
    }

    public List<BtcChildAddress> getBtcChildAddresses() {
        return btcChildAddresses;
    }

    public void setBtcChildAddresses(List<BtcChildAddress> btcChildAddresses) {
        this.btcChildAddresses = btcChildAddresses;
    }

}
